****TABLE A2****

cd "$main_dir/output/tables/appendix_a"

global basic 	sex marital religion edu

//--------------------------------------------------------
//Read in relevant datasets
//--------------------------------------------------------

clear
use "$data_dir/clean/harmonized_dataset.dta"

local files : dir "$data_dir/raw/lifeexp_variables_data/" files "*.dta"
foreach f in `files' {
	merge m:1 ccode survey_year yob using "$data_dir/raw/lifeexp_variables_data/`f'", nogen
	di "`f' merged"
}

fegen subregion_yob = group(subregion yob) if yob!=-99
fegen svy_survey_year = group(survey_year survey)

cap drop sample
gen sample = 1 if born_country!=0 & total_growth_rate_obs>=0.9*(age-1) & total_growth_rate_obs!=.
qui reghdfe trust_govt wgrowth_rate_1 yob_ln_gdppc if sample==1, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
keep if e(sample)==1

//--------------------------------------------------------
//Create Table A2
//--------------------------------------------------------

keep trust_govt trust_state trust_others trust_religious_organizations govt_corrupt feelings_income standard_living wgrowth_rate_1 wprop_unrest_1 wno_exec_changes_1 wprop_affect_epidemic_1 wbank_crisis_1 wcurrency_crisis_1 wtwin_crisis_1 wwinsz_inflation_1 sd_winsz_inflation wv2x_polyarchy_1 wv2xel_frefair_1 wv2x_jucon_1 wv2xlg_legcon_1 wv2x_freexp_1 wv2mecenefm_1 fy_growth_rate preyob_growth_rate_5 preyob_growth_rate_10 preyob_growth_rate_15 wgrowth_shock_1 wdisaster_1 wacceleration_1
order trust_govt trust_state trust_others trust_religious_organizations govt_corrupt feelings_income standard_living wgrowth_rate_1 wprop_unrest_1 wno_exec_changes_1 wprop_affect_epidemic_1 wbank_crisis_1 wcurrency_crisis_1 wtwin_crisis_1 wwinsz_inflation_1 sd_winsz_inflation wv2x_polyarchy_1 wv2xel_frefair_1 wv2x_jucon_1 wv2xlg_legcon_1 wv2x_freexp_1 wv2mecenefm_1 fy_growth_rate preyob_growth_rate_5 preyob_growth_rate_10 preyob_growth_rate_15 wgrowth_shock_1 wdisaster_1 wacceleration_1

outreg2 using table_a2, sum(log) replace
